﻿using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.WordResExcel
{
    public class WordResExcelController : Controller
    {
        public IActionResult Word()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            PageOfficeNetCore.Word.WordDocumentWriter worddoc = new PageOfficeNetCore.Word.WordDocumentWriter();
            //先在要插入word文件的位置手动插入书签,书签必须以“PO_”为前缀
            //给DataRegion赋值,值的形式为："[word]word文件路径[/word]"
            PageOfficeNetCore.Word.DataRegionWriter data1 = worddoc.OpenDataRegion("PO_p1");
            data1.Value = "[excel]/WordResExcel/doc/1.xls[/excel]";
            PageOfficeNetCore.Word.DataRegionWriter data2 = worddoc.OpenDataRegion("PO_p2");
            data2.Value = "[word]/WordResExcel/doc/2.doc[/word]";
            PageOfficeNetCore.Word.DataRegionWriter data3 = worddoc.OpenDataRegion("PO_p3");
            data3.Value = "[word]/WordResExcel/doc/3.doc[/word]";

            poCtrl.SetWriter(worddoc);
            //打开Word文档
            poCtrl.WebOpen("doc/test.doc", PageOfficeNetCore.OpenModeType.docNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }
    }
}